package Week6;

import java.util.*;

public class Day34 {
}

//牛客:ISBN号码
class Main9 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        char[] s = in.next().toCharArray();
        int sum = 0, count = 1, n = s.length;
        for (int i = 0; i < n - 1; i++) {
            if (s[i] >= '0' && s[i] <= '9') {
                sum += (s[i] - '0') * count;
                count++;
            }
        }
        sum %= 11;
        if (sum == s[n - 1] - '0' || sum == 10 && s[n - 1] == 'X') {
            System.out.println("Right");
        } else {
            s[n - 1] = sum == 10 ? 'X' : (char)(sum + '0');
            for (int i = 0; i < n; i++) {
                System.out.print(s[i]);
            }
        }
    }
}

//牛客:kotori和迷宫
class Main10{
    public static int N = 35;
    public static int x1, y1; // 记录起始位置
    public static int n, m;
    public static char[][] arr = new char[N][N];
    public static int[][] dist = new int[N][N];
    public static int[] dx = {0, 0, 1, -1};
    public static int[] dy = {1, -1, 0, 0};
    public static void bfs(){
        for(int i = 0; i < n; i++){
            for(int j = 0; j < m; j++){
                dist[i][j] = -1;
            }
        }
        Queue<int[]> q = new LinkedList<>();
        q.add(new int[]{x1, y1});
        dist[x1][y1] = 0;
        while(!q.isEmpty()){
            int[] tmp = q.poll();
            int a = tmp[0], b = tmp[1];
            for(int i = 0; i < 4; i++){
                int x = a + dx[i], y = b + dy[i];
                if(x >= 0 && x < n && y >= 0 && y < m && arr[x][y] != '*' && dist[x][y] == -1){
                    dist[x][y] = dist[a][b] + 1;
                    if(arr[x][y] != 'e'){
                        q.add(new int[]{x, y});
                    }
                }
            }
        }
    }
    public static void main(String[] s){
        Scanner in = new Scanner(System.in);
        n = in.nextInt(); m = in.nextInt();
        for(int i = 0; i < n; i++){
            char[] tmp = in.next().toCharArray();
            for(int j = 0; j < m; j++){
                arr[i][j] = tmp[j];
                if(arr[i][j] == 'k'){
                    x1 = i; y1 = j;
                }
            }
        }
        bfs();
        // 更新结果
        int count = 0, ret = 1000;
        for(int i = 0; i < n; i++){
            for(int j = 0; j < m; j++)
            {
                if(arr[i][j] == 'e' && dist[i][j] != -1){
                    count++;
                    ret = Math.min(ret, dist[i][j]);
                }
            }
        }
        if(count == 0) System.out.println(-1);
        else System.out.println(count + " " + ret);
    }
}

//牛客:NC138 矩阵最长递增路径
class Solution2 {
    int m, n;
    int[] dx = {0, 0, 1, -1};
    int[] dy = {1, -1, 0, 0};
    int[][] memo = new int[1010][1010];
    public int dfs(int[][] matrix, int i, int j) {
        if (memo[i][j] != -1) return memo[i][j];
        int len = 1;
        for (int k = 0; k < 4; k++) {
            int x = i + dx[k], y = j + dy[k];
            if (x >= 0 && x < m && y >= 0 && y < n && matrix[x][y] > matrix[i]
                    [j]) {
                len = Math.max(len, 1 + dfs(matrix, x, y));
            }
        }
        memo[i][j] = len;
        return len;
    }
    public int solve (int[][] matrix) {
        m = matrix.length;
        n = matrix[0].length;
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                memo[i][j] = -1;
            }
        }
        int ret = 1;
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                ret = Math.max(ret, dfs(matrix, i, j));
            }
        }
        return ret;
    }
}